<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'datasouce_maint.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<script src='<%=basePath %>/dwr/interface/SystemService.js'></script>
	<script src='<%=basePath %>/dwr/engine.js'></script>
	<script type="text/javascript" src="<%=basePath%>/js/jquery.js"></script>
	<script type="text/javascript" src='<%=basePath %>/js/jquery.blockUI.js'></script>
	<script type="text/javascript" src='<%=basePath %>/admin/datasource/js/customized.js'></script>
	<style type="text/css"> 
	/* CSS Document */ 
	
	body { 
	    font: normal 12px auto "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; 
	    color: #4f6b72; 
	    background: #E6EAE9; 
	} 
	
	a { 
	    color: #c75f3e; 
	} 
	
	#mytable { 
	    width: 1000px; 
	    padding: 0; 
	    margin: 0; 
	    margin: auto;
	} 
	
	caption { 
	    padding: 0 0 5px 0; 
	    width: 700px;      
	    font: italic 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; 
	    text-align: right; 
	} 
	
	th { 
	    font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; 
	    color: #4f6b72; 
	    border-right: 1px solid #C1DAD7; 
	    border-bottom: 1px solid #C1DAD7; 
	    border-top: 1px solid #C1DAD7; 
	    letter-spacing: 2px; 
	    text-transform: uppercase; 
	    text-align: left; 
	    padding: 6px 6px 6px 12px; 
	    background: #CAE8EA url(images/bg_header.jpg) no-repeat; 
	} 
	
	th.nobg { 
	    border-top: 0; 
	    border-left: 0; 
	    border-right: 1px solid #C1DAD7; 
	    background: none; 
	} 
	
	td { 
	    border-right: 1px solid #C1DAD7; 
	    border-bottom: 1px solid #C1DAD7; 
	    background: #fff; 
	    font-size:11px; 
	    padding: 6px 6px 6px 12px; 
	    color: #4f6b72; 
	} 
	
	
	td.alt { 
	    background: #F5FAFA; 
	    color: #797268; 
	} 
	
	th.spec { 
	    border-left: 1px solid #C1DAD7; 
	    border-top: 0; 
	    background: #fff url(images/bullet1.gif) no-repeat; 
	    font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; 
	} 
	
	th.specalt { 
	    border-left: 1px solid #C1DAD7; 
	    border-top: 0; 
	    background: #f5fafa url(images/bullet2.gif) no-repeat; 
	    font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; 
	    color: #797268; 
	} 
	/*---------for IE 5.x bug*/ 
	html>body td{ font-size:11px;} 
	
	.pbtn3 {
		width:100px;
		height:30px;
		text-indent:0px;
		padding-bottom:4px;
		color:#4f6b72;
		
	}
	
	.testConn {
		background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #ffc477), color-stop(1, #f0972b) );
		background:-moz-linear-gradient( center top, #ffc477 5%, #f0972b 100% );
		filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffc477', endColorstr='#f0972b');
		background-color:#f0972b;
		border:1px solid #eeb44f;
		display:inline-block;
		color:#ffffff;
		font-family:Arial;
		font-size:15px;
		font-weight:bold;
		padding:6px 24px;
		text-decoration:none;
	}
	
	.testConn:active {
		position:relative;
		top:1px;
	}
	</style> 
	
	<script type="text/javascript">
		
		function getDataSouce(){
			showBlock("body");
			var ds = $("#dses") ;
			ds.empty();
			SystemService.getDataSources(function(data) {
				if(data) {
					for(var i=0;i<data.length;i++) {
						var cur = data[i] ;
						var tr = '<tr>'+
									'<th scope="row" abbr="Model" class="spec"><input type="checkbox" id="checkedDs" value="'+cur.id+'"/></th>'+
									'<td>'+cur.id+'</td>'+
									'<td>'+cur.databaseType+'</td>'+
									'<td>'+cur.dataSourceIp+'</td>'+
									'<td>'+cur.databaseName+'</td>'+
									'<td>'+cur.username+'</td>'+
									'<td>'+cur.password+'</td>'+
									'<td>'+cur.regeUsername+'</td>'+
							 		'<td>'+cur.regDate+'</td>'+
							 		'<td><a href="javascript:testConnection(\''+i+'\')" id="a'+i+'" class="testConn" data="'+cur.id+'">测试连接</a></td>'+
								 '</tr>';
							ds.append(tr);
					}
				}
				$("body").unblock();
			});
		}
	
		$(function(){
			getDataSouce();
		}) ;
		
		function testConnection(id) {
			var connId = $("#dses #a"+id).attr("data") ;
			SystemService.testConnection(connId,function(data) {
				if(data=="true") {
					$("#dses #a"+id).css("background","green");
				}else {
					$("#dses #a"+id).css("background","red");
				}
			}) ;
		}
		
		function deleteDs() {
			var ids = [];
			$("input[type='checkbox']:checked").each(function(){ 
			   ids.push($(this).val());
			});
			SystemService.deleteById(ids,function(data){
				alert(data);
				getDataSouce();
			});
		}
		
		function modify() {
			var ids = [];
			$("input[type='checkbox']:checked").each(function(){ 
			   ids.push($(this).val());
			});
			if(ids.length<=0) {
				alert("必须选择一个");
				return;
			}
			if(ids.length>1) {
				alert("一次只能修改一个");
				return;
			}
			window.location.href='<%=basePath%>/admin/datasource/modify.jsp?id='+ids[0] ;
		}
	
	</script>
  </head>
  
  <body>
  		<div style="margin-top: 20px;"></div>
  		<h3 align="center">数据源管理</h3>
  		<hr>
		<table id="mytable" cellspacing="0" > 
		   <tr> 
		   	 <th scope="col"></th> 
		    <th scope="col" >编号</th> 
		    <th scope="col" >数据库类型</th> 
		    <th scope="col">数据源IP</th> 
		    <th scope="col">数据库名</th> 
		     <th scope="col">数据库用户</th> 
		    <th scope="col">连接密码</th> 
		    <th scope="col">注册人员</th> 
		    <th scope="col">注册时间</th> 
		      <th scope="col"></th> 
		  </tr> 
		 <tbody id="dses">
		
		 </tbody>
		  <tr>
  			<td colspan="5" align="right"><button type="button" class="pbtn3" onclick="modify()">修改</button></td>
  			<td colspan="5"><button type="button" class="pbtn3" onclick="deleteDs()">删除</button></td>
  		  </tr>
		
		</table> 
  		
  </body>
</html>
